﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourCustomization
    {
        #region Common
        public eTourCustomization Data;

        public TourCustomization()
        {
            Data = new eTourCustomization();
        }

        ~TourCustomization()
        {
        }

        public virtual void Dispose()
        {
        }

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cTourCustomization objDAL = new cTourCustomization();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cTourCustomization objDAL = new cTourCustomization();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;

                objDAL.Save();
                nResult = objDAL.TourCustomizationID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public void LoadById(int ID)
        {
            cTourCustomization objDAL = new cTourCustomization();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cTourCustomization objInfor = new cTourCustomization();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourCustomizationID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cTourCustomization objInfor = new cTourCustomization();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        private void MappingData(cTourCustomization objInfor)
        {
            try { objInfor.Address = Data.Address; }
            catch { objInfor.Address = ""; }
            objInfor.Adults = Data.Adults;
            objInfor.Children = Data.Children;
            try { objInfor.CityName = Data.CityName; }
            catch { objInfor.CityName = ""; }
            objInfor.CountryID = Data.CountryID;
            objInfor.DurationID = Data.DurationID;
            try { objInfor.Email = Data.Email; }
            catch { objInfor.Email = ""; }
            objInfor.ExpectedDepartureDate = Data.ExpectedDepartureDate;
            try { objInfor.Fax = Data.Fax; }
            catch { objInfor.Fax = ""; }
            try { objInfor.FullName = Data.FullName; }
            catch { objInfor.FullName = ""; }
            objInfor.GuideID = Data.GuideID;
            try { objInfor.GuideSuggestion = Data.GuideSuggestion; }
            catch { objInfor.GuideSuggestion = ""; }
            try { objInfor.OtherRequest = Data.OtherRequest; }
            catch { objInfor.OtherRequest = ""; }
            objInfor.PaymentID = Data.PaymentID;
            objInfor.PortOfArrivalID = Data.PortOfArrivalID;
            try { objInfor.Telephone = Data.Telephone; }
            catch { objInfor.Telephone = ""; }
            try { objInfor.TourCategorySuggestion = Data.TourCategorySuggestion; }
            catch { objInfor.TourCategorySuggestion = ""; }
            try { objInfor.VisitationSuggestion = Data.VisitationSuggestion; }
            catch { objInfor.VisitationSuggestion = ""; }
            objInfor.BookingDate = Data.BookingDate;
            objInfor.Status = Data.Status;
            objInfor.EverHeard = Data.EverHeard;
        }

        private void ConvertData(cTourCustomization objInfor)
        {
            Data.Address = objInfor.Address;
            Data.Adults = objInfor.Adults;
            Data.Children = objInfor.Children;
            Data.CityName = objInfor.CityName;
            Data.CountryID = objInfor.CountryID;
            Data.DurationID = objInfor.DurationID;
            Data.Email = objInfor.Email;
            Data.ExpectedDepartureDate = objInfor.ExpectedDepartureDate;
            Data.Fax = objInfor.Fax;
            Data.FullName = objInfor.FullName;
            Data.GuideID = objInfor.GuideID;
            Data.GuideSuggestion = objInfor.GuideSuggestion;
            Data.OtherRequest = objInfor.OtherRequest;
            Data.PaymentID = objInfor.PaymentID;
            Data.PortOfArrivalID = objInfor.PortOfArrivalID;
            Data.Telephone = objInfor.Telephone;
            Data.TourCategorySuggestion = objInfor.TourCategorySuggestion;
            Data.VisitationSuggestion = objInfor.VisitationSuggestion;
            Data.BookingDate = objInfor.BookingDate;
            Data.Status = objInfor.Status;
            Data.EverHeard = objInfor.EverHeard;
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cTourCustomization objDAL = new cTourCustomization();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
        public DataTable Search(int ItemID, int ItemView, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cTourCustomization objDAL = new cTourCustomization();
            tbResult = objDAL.Search(ItemID, ItemView, PageIndex, PageSize, ref PageCount);
            return tbResult;
        }
        #endregion
    }
}